// src/main/java/com/example/coursehub/repository/CourseTeacherRepository.java
package com.example.coursehub.repository;

import com.example.coursehub.entity.CourseTeacher;
import com.example.coursehub.entity.CourseTeacherId;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Optional;


public interface CourseTeacherRepository extends JpaRepository<CourseTeacher, CourseTeacherId>, JpaSpecificationExecutor<CourseTeacher> {

    List<CourseTeacher> findByCourse_CourseId(String courseId);
    List<CourseTeacher> findByUser_UserId(String userId);
    Optional<CourseTeacher> findByCourse_CourseIdAndUser_UserId(String courseId, String userId);
    void deleteByCourse_CourseIdAndUser_UserId(String courseId, String userId);

    boolean existsById_courseIdAndId_userId(String courseId, String userId);

    @Query("SELECT EXISTS(SELECT ct FROM CourseTeacher ct WHERE ct.id.courseId = :courseId AND ct.id.userId = :userId)")
    boolean existsByCourseIdAndUserId(@Param("courseId") String courseId, @Param("userId") String userId);
}